<template>
  <div>
    <p>1、密码有效期  <el-input-number v-model="password_validity" :min="1" size="mini" label="描述文字"></el-input-number>  天，超过有效期，必须修改密码。</p>
    <p>2、密码连续输入失败 <el-input-number v-model="login_failures" :min="1" size="mini" label="描述文字"></el-input-number>  次，锁定账号 <el-input-number v-model="lock_time" :min="1" size="mini" label="描述文字"></el-input-number>  分钟</p>
    <p>3、密码难度设置8位以上（至少选三项）</p>
    <el-checkbox-group v-model="password_difficulty">
      <el-checkbox label="1">英文大写字母A-Z</el-checkbox>
      <el-checkbox label="2">小写字母a-z</el-checkbox>
      <el-checkbox label="3">数字0-9</el-checkbox>
      <el-checkbox label="4">特殊字符（如！、@、#、￥、%等）</el-checkbox>
    </el-checkbox-group>
    <p>操作退出设置，<el-input-number v-model="exit_without_operation" :min="1" size="mini" label="描述文字"></el-input-number> 分钟，无操作自动退出</p>
    <el-row v-if="this.menuList.includes('saveSystem')">
      <el-col :offset="15" :span="2"><el-button type="primary" @click="submit()">保存</el-button></el-col>
    </el-row>
  </div>
</template>
<script>
import {APIADDSYSTEMSETTING, APIGETSYSTEMSETTING} from '@/common/api.js'
export default {
  data () {
    return {
      menuList: [],
      password_validity: 90,
      login_failures: 3,
      lock_time: 30,
      password_difficulty: [],
      exit_without_operation: 30
    }
  },
  created () {
    this.menuList = sessionStorage.getItem('list')
    this.tableList()
  },
  methods: {
    tableList () {
      APIGETSYSTEMSETTING().then((res) => {
        this.password_validity = res.data.password_validity
        this.login_failures = res.data.login_failures
        this.lock_time = res.data.lock_time
        this.password_difficulty = res.data.password_difficulty.split(',')
        this.exit_without_operation = res.data.exit_without_operation
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    },
    submit () {
      APIADDSYSTEMSETTING({
        password_validity: this.password_validity,
        login_failures: this.login_failures,
        lock_time: this.lock_time,
        password_difficulty: this.password_difficulty.toString(),
        exit_without_operation: this.exit_without_operation
      }).then((res) => {
        this.$message.success(res.msg)
        sessionStorage.setItem('exit_without_operation', this.exit_without_operation)
        // location.reload()
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    }
  }
}
</script>
